// components/publisher_list/publisher_list.js
const mybehavior = require("../../behaviors/requests")
Component({
  // 修改组件vant的样式
  options: {
    styleIsolation: 'shared',
  },
  behaviors: [mybehavior],
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    list: [],
    base_urlstr: "https://logisticsengineering.gree.com",
  },

  /**
   * 组件的方法列表
   */
  methods: {
    get_demand_publisher() {
      var url = this.data.base_urlstr + "/order_system/reverse/find_demand";
      var data = {}
      this.post(url, data).then(res => {
        if (res.code == 20000) {
          this.setData({
            list: res.data
          })
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'error'
          })
        }
      }).catch(err => {
        wx.showToast({
          title: err.msg,
          icon: 'error'
        })
      })
    },
    delete_employee(ev) {
      var url = this.data.base_urlstr + "/order_system/reverse/delete_demand";
      var data = {
        employee_num: ev.currentTarget.dataset.staff_code
      }
      this.post(url, data).then(res => {
        if (res.code == 20000) {
          wx.showToast({
            title: res.msg,
            icon: 'success'
          })
          this.get_demand_publisher()
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'error'
          })
        }
      }).catch(err => {
        wx.showToast({
          title: err.msg,
          icon: 'error'
        })
      })
    }
  },
  lifetimes: {
    attached: function () {
      this.get_demand_publisher();
    },
    ready: function () {

    },
    detached: function () {

    },
  }
})